﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string.h>
#include <math.h>
#include <unordered_map>
using namespace std;

class Solution {
public:
    int trap(vector<int>& height) {
        int leftMax = 0, rightMax = 0, left = 0, right = height.size() - 1;
        int ret = 0;
        while (left < right)
        {
            leftMax = max(leftMax, height[left]);
            rightMax = max(rightMax, height[right]);
            if (height[left] < height[right])
            {
                ret += leftMax - height[left];
                left++;
            }
            else if (height[left] >= height[right])
            {
                ret += rightMax - height[right];
                right--;
            }
        }
        return ret;
    }
};

int main()
{
    vector<int> arr(10, 0);
    return 0;
}
